<?php

class BedrijfsbegeleiderForm extends Form
{
	const L_FIELD_REQUIRED = 'Dit veld is verplicht';

	public function __construct( $data = array() )
	{
		parent::__construct( );
		
		if( isset( $data['id'] ) )
		{
			$this->addChild( new InputHidden( 'id', $data['id'] ) );
		}
		
		$persoonsgegevens = new FieldSet( 'Persoonsgegevens' );
		
		$voornaam = new InputText( 'first_name', Docent::getField('first_name'), isset( $data[ 'first_name' ] ) ? $data[ 'first_name' ] : '', 'firstname' );
		$voornaam->getValidator()->required( self::L_FIELD_REQUIRED );
		$persoonsgegevens->addChild( $voornaam );
		
		$achternaam = new InputText( 'last_name', Docent::getField('last_name'), isset( $data[ 'last_name' ] ) ? $data[ 'last_name' ] : '', 'lastname' );
		$achternaam->getValidator()->required( self::L_FIELD_REQUIRED );
		$persoonsgegevens->addChild( $achternaam );
		
		$geslacht = new RadioButtonContainer( 'gender', true, 'gender' );
		$geslacht->addChild( new RadioButton( 'm', 'Man' ) );
		$geslacht->addChild( new RadioButton( 'v', 'Vrouw' ) );
		
		if ( isset( $data[ 'gender_c' ] ) )
		{
			$geslacht->setSelected( $data[ 'gender' ] );
		}
		
		$persoonsgegevens->addChild( $geslacht );

		$this->addChild( $persoonsgegevens );
		
		$adresgegevens = new FieldSet( 'Adres' );
		
		$straat = new InputText( 'primary_address_street', Docent::getField('primary_address_street'), isset( $data[ 'primary_address_street' ] ) ? $data[ 'primary_address_street' ] : '', 'street' );
		$straat->getValidator()->required( self::L_FIELD_REQUIRED );
		$adresgegevens->addChild( $straat );
		
		$postal = new InputText( 'primary_address_postalcode', Docent::getField('primary_address_postalcode'), isset( $data[ 'primary_address_postalcode' ] ) ? $data[ 'primary_address_postalcode' ] : '', 'postal' );
		$postal->getValidator()->required( self::L_FIELD_REQUIRED );
		$postal->getValidator()->compareMatch('^([1-9]{1}[0-9]{3})[[:space:]]*([a-zA-Z]{2})$', 'U moet een geldige postcode invullen.');
		$adresgegevens->addChild( $postal );
		
		$city = new InputText( 'primary_address_city', Docent::getField('primary_address_city'), isset( $data[ 'primary_address_city' ] ) ? $data[ 'primary_address_city' ] : '', 'city' );
		$city->getValidator()->required( self::L_FIELD_REQUIRED );
		$adresgegevens->addChild( $city );
		
		$this->addChild( $adresgegevens );
		
		$contact = new FieldSet('Contact');
		
		$phone = new InputText( 'phone_home', Docent::getField('phone_home'), isset( $data[ 'phone_home' ] ) ? $data[ 'phone_home' ] : '', 'phone' );
		$phone->getValidator()->required( self::L_FIELD_REQUIRED );
		$contact->addChild( $phone );
		
		$phone = new InputText( 'phone_mobile', Docent::getField('phone_mobile'), isset( $data[ 'phone_mobile' ] ) ? $data[ 'phone_mobile' ] : '', 'phone' );
		$phone->getValidator()->required( self::L_FIELD_REQUIRED );
		$contact->addChild( $phone );
		
		$email = new InputText( 'email1', Docent::getField('email1'), isset( $data[ 'email1' ] ) ? $data[ 'email1' ] : '', 'email' );
		$email->getValidator()->required( self::L_FIELD_REQUIRED );
		$email->getValidator()->compareMatch( ElementValidation::REGEX_EMAIL, 'Wel een geldig e-mail adres invullen he!' );
		$contact->addChild( $email );
		
		$facultyField = Docent::getField('faculty');
		$faculty = new SelectOneChoice( 'faculty', $facultyField  );
		$faculty->addValues( $facultyField->getOptions() );
		$faculty->setSelected( isset( $data[ 'education_c' ] ) ? $data[ 'education_c' ] : $facultyField->getDefaultValue() );
		$contact->addChild( $faculty );
		
		$this->addChild( $contact );
		
		$this->addChild( new SubmitButton( 'submit', 'Opslaan' ) );
	}
}
